using System;
using System.Diagnostics.CodeAnalysis;
using BI.Commons.ExtensionMethods;

namespace BankInvest.InstrumentEditor.Domain.Entities
{
    public class InstrumentType
    {
        private readonly int _id;
        private readonly string _name;

        /// <summary><remarks>NHibernate needs parameter-less ctor</remarks></summary>
        [ExcludeFromCodeCoverage]
        protected InstrumentType() { }

        public InstrumentType(int id) : this(id, null) { }

        public InstrumentType(int id, string name)
        {
            _id = id;
            _name = name;
        }

        public virtual int Id { get { return _id; } }

        public virtual string Name { get { return _name; } }

        public virtual bool Equals(InstrumentType other)
        {
            if (ReferenceEquals(null, other)) return false;

            return other._id == _id;
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as InstrumentType);
        }

        public override int GetHashCode()
        {
            return _id;
        }

        public override string ToString()
        {
            return "#{0}: {1}".FormatWith(_id, _name ?? "[null]");
        }
    }
}